/*
package cn.itcast.bos.web.action.base;


import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.service.base.CourierService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;

import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.HashMap;

@ParentPackage("json-default")
@Controller
@Namespace("/")
@Scope("prototype")
public class CouriersAction extends ActionSupport implements ModelDriven<Courier> {

    private Courier c = new Courier();
    @Override
    public Courier getModel() {
        return c;
    }

    @Autowired
    private CourierService courierService;

    @Action(value = "couriers_save",results = {@Result(name = "success",type = "redirect",location = "./pages/base/courier.html")})
    public String save(){
        courierService.save(c);
        return SUCCESS;
    }

    private int page;
    private int rows;

    public void setPage(int page) {
        this.page = page;
    }
    public void setRows(int rows) {
        this.rows = rows;
    }

    @Action(value = "couriers_pageQuery",results = {@Result(name = "success",type = "json")})
    public String findByPage(){
        // 封装Pageable对象
        Pageable pageable = new PageRequest(page - 1, rows);

        Specification<Courier> specification = new Specification<Courier>() {
            @Override
            public Predicate toPredicate(Root<Courier> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                // Root 用于获取属性字段，CriteriaQuery可以用于简单条件查询，CriteriaBuilder 用于构造复杂条件查询
                ArrayList<Predicate> list = new ArrayList<>();

                // 进行快递员工工号查询 courierNum=？
                if (StringUtils.isNotBlank(c.getCourierNum())){
                    Predicate p1 = criteriaBuilder.equal(root.get("courierNum").as(String.class), c.getCourierNum());
                    list.add(p1);
                }

                //进行所属单位查询  company  模糊查询
                if(StringUtils.isNotBlank(c.getCompany())){
                    Predicate p2 = criteriaBuilder.like(root.get("company").as(String.class), "%"+c.getCompany()+"%");
                    list.add(p2);
                }

                //进行类型查询 type
                if (StringUtils.isNotBlank(c.getType())){
                    Predicate p3 = criteriaBuilder.equal(root.get("type").as(String.class), c.getType());
                    list.add(p3);
                }

                // 多表查询(查询当前对象 关联对象 对应数据表)
                //使用Courier（root），关联standard
                Join<Object, Object> standardRoot = root.join("standard", JoinType.INNER);
                if (c.getStandard() !=null &&StringUtils.isNotBlank(c.getStandard().getName())){
                    Predicate p4 = criteriaBuilder.like(standardRoot.get("name").as(String.class), "%"+c.getStandard().getName() + "%");
                    list.add(p4);
                }
                return criteriaBuilder.and(list.toArray(new Predicate[0]));
            }
        };


        // 调用业务层 ，返回 Page
        Page<Courier> courierPage = courierService.findPageData(specification,pageable);
        // 将返回page对象 转换datagrid需要格式
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",courierPage.getTotalElements());
        map.put("rows",courierPage.getContent());
        // 将结果对象 压入值栈顶部
//        ActionContext.getContext().getValueStack().push(map);
        ActionContext.getContext().getValueStack().push(map);


        return SUCCESS;
    }







}
*/
